function [yyy, output,pars, model]=calibrate_money_demand_fuc1(ppp,x,tradep,otherpar,data,ssopt)

%===============================================
% Parameters identified outside the model
%% ===============================================

%% ========================================================================
% Match money demand curve:
%==========================================================================

% Pass Variables
alpha1 = otherpar.alpha1;
alpha2 = otherpar.alpha2;
alpha3 = otherpar.alpha3;
otherpar.theta = ppp; %bargaining power to the buyers



%=================================================
% Production function of firms f(k)=A*k^(eta)
%================================================
trading_prob = tradep; % total trading prob

alpha1 = alpha1*trading_prob;

alpha2 = alpha2*trading_prob;

alpha3= alpha3*trading_prob;



%% ==========================================================================
% Match the money demand curve
%==========================================================================
% Define Initial guess x0 of parameters x=[sigma,B] where
% sigma is DM utility curvature and B is the coefficient on the CM utility 
x0=[0.8,4];
xlow=[0,0]; % Lower bound for matching money demand curve
xhigh=[3,10]; % upper bound for matching money demand

% nonlinear least squares to match the money deman curve
% generate model predicted money demand curve plotted against data
%[yy,model,eq,model_fit]=cal_MD_v2(x,i_D,pi_m,data,A,otherpar,eta,alpha1,alpha2,alpha3,1); % generate model prediction
[yy,model,output]=cal_MD_v2(x,data,otherpar,alpha1,alpha2,alpha3,ssopt); % generate model prediction



yyy=output(1)-1.2
pars = [yy,ppp, x];
%pars=[x,theta]
%save(['pars_post',num2str(trading_prob*10)],'pars')
%save(['model_fit_',num2str(trading_prob*10)],'yy')
